<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    title="做法"
    :canFullscreen="false"
    :width="1000"
    :destroyOnClose="true"
    @ok="handleSubmit"
  >
    <div>
      <Practice ref="practiceRef" />
    </div>
  </BasicModal>
</template>
<script lang="ts" setup>
  import { ref } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import Practice from './components/practice/Index.vue';

  const emit = defineEmits<{
    (e: 'selectRowList', practiceList: any[]): void;
  }>();
  const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
    setModalProps({ confirmLoading: false });
  });

  async function handleSubmit() {
    try {
      let practiceList = practiceRef.value.getSelectRowList();

      emit('selectRowList', practiceList);
      console.log(practiceList);

      setModalProps({ confirmLoading: true });
      closeModal();
    } finally {
      setModalProps({ confirmLoading: false });
    }
  }

  const practiceRef = ref<{ getSelectRowList: () => any; data: any[] } | null>(null);

  defineExpose({
    registerModal,
    handleSubmit,
  });
</script>
<style lang="less" scoped>
  .background {
    background-color: @body-background;
  }
</style>
